/**
 * Created by 121 on 2016/4/08.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog',
    'calendar',
    'highCharts'
], function ($, common, ready, template, Collection, Model, dialog, calendar, highCharts) {

    var index = function () {
        this.init();
    };
    var id = getUrlPath(4);
    index.prototype = {
        init: function () {
            this.event();
            //this.fetch();
        },
        event: function () {
            var _this = this;
            var success = function (status) {
                $.ajax({
                    url: _global.url.api + 'site_data/' + id,
                    type: 'get',
                    data: {status: status},
                    success: function (res) {
                        var data = res.data;
                        console.log(res.data_time);
                        $("#day_sale").html(data[3][0][0]);
                        $("#amount").html('&nbsp' + data[2]['amount'] + '&nbsp' + '元');
                        $("#day_order").html(data[3][0][1]);
                        $("#order").html('&nbsp' + data[2]['orders'] + '&nbsp' + '单');
                        $("#all_sale").html(data[3][0][2]);
                        $("#amounts").html('&nbsp' + data[4]['amount'] + '&nbsp' + '元');
                        $("#all_order").html(data[3][0][3]);
                        $("#orders").html('&nbsp' + data[4]['orders'] + '&nbsp' + '单');
                        $("#site_name").html(data[5]['name'] + '&nbsp');
                        $("#site_id").html('&nbsp' + '(' + 'ID:' + '&nbsp' + data[5]['id'] + ')')
                        $('#high_charts').highcharts({
                            chart: {
                                zoomType: 'xy'
                            },
                            title: {
                                text: ''
                            },
                            xAxis: [{
                                categories: res.data_time,
                                format: '{value}' + res.data[3][0][4],
                                labels: {
                                    formatter: function () {
                                        return this.value + data[3][0][4];
                                    }
                                }
                            },
                            ],
                            yAxis: [{ // Primary yAxis
                                labels: {
                                    format: '{value}单',
                                    style: {
                                        color: '#89A54E'
                                    }

                                },
                                title: {
                                    text: '订单数',
                                    style: {
                                        color: '#89A54E'
                                    }
                                },
                                lineWidth: 2
                            }, { // Secondary yAxis
                                title: {
                                    text: '销售额',
                                    style: {
                                        color: '#4572A7'
                                    }
                                },
                                labels: {
                                    format: '{value}元',
                                    style: {
                                        color: '#4572A7'
                                    }
                                },
                                lineWidth: 2,
                                opposite: true
                            }],
                            tooltip: {
                                shared: true
                            },
                            legend: {
                                layout: 'vertical',
                                verticalAlign: 'top',
                                floating: true,
                                backgroundColor: '#FFFFFF'
                            },
                            series: [{
                                name: '销售额',
                                color: '#4572A7',
                                type: 'spline',
                                yAxis: 1,
                                data: res.data[0],
                                tooltip: {
                                    valueSuffix: ' 元'
                                }

                            }, {
                                name: '成交笔数',
                                color: '#89A54E',
                                type: 'spline',
                                yAxis: 0,
                                data: res.data[1],
                                tooltip: {
                                    valueSuffix: '个'
                                }
                            }]
                        });
                    }
                });
            }
            success();
            $('#btn-success-status').find('a').on('click', function (e) {
                $(this).siblings().removeClass('active');
                e.preventDefault();
                var status = $(e.target).attr('rel');
                success(status);
            });
        }
    };
    new index();
});